

/*------------------------------------------------------------------------------
	1. Housekeepings
------------------------------------------------------------------------------*/

	*Settings
		set more off
		pause off
		clear
	
	*Set Globals
		global data = "...\Data"
		global output = "...\Output\Tables"
		
		
/*------------------------------------------------------------------------------
	2. Create Table 1:
------------------------------------------------------------------------------*/	
import excel using "${data}\table_backup_data.xlsx", clear first sheet("by_state")
	sort state
	foreach i of varlist perc_claimed2017 perc_claimed2018 perc_claimed2019 perc_claimed2020 perc_claimed2021 {
		replace `i' = `i' * 100
		mkmat `i', matrix(`i')
		mat `i' = `i''
		
		levelsof state, local(state)
		mat coln `i' = `state'
}
	

	cap program drop claim_dat
	program claim_dat, eclass
		*returned in e() structure
		foreach i of varlist perc_claimed2017 perc_claimed2018 perc_claimed2019 perc_claimed2020 perc_claimed2021 {
			eret mat `i' = `i'
		}
	end

	estimates clear
	eststo clear

	claim_dat
	
#delimit ;


esttab using "$output/by_state.tex", replace
	booktabs nogaps label noobs collabels(none) nonumber eqlabels(none) nomtitles 
	cells("perc_claimed2017 (fmt(%10.1fc)) perc_claimed2018 (fmt(%10.1fc)) perc_claimed2019 (fmt(%10.1fc)) perc_claimed2020 (fmt(%10.1fc)) perc_claimed2021 (fmt(%10.1fc))") 
	prehead(\begin{table}[htbp]   
			\footnotesize
			\caption{Share Claimed (\%) by State} 
			\label{tab:by_state}
			\makebox[\textwidth][c]{
			\centering                                      
			\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}                        
			\begin{tabular}{l*{1}{ccccc}}   
			\toprule
			&\multicolumn{1}{c}{(1)} & \multicolumn{1}{c}{(2)} &\multicolumn{1}{c}{(3)} & \multicolumn{1}{c}{(4)} &\multicolumn{1}{c}{(5)} \\                            
			\cmidrule(lr){2-6}
			& \multicolumn{1}{c}{2017} & \multicolumn{1}{c}{2018} & \multicolumn{1}{c}{2019} & \multicolumn{1}{c}{2020} & \multicolumn{1}{c}{2021}  \\                
			\midrule) 
	postfoot(\midrule                  
			\multicolumn{6}{p{1in}}{\footnotesize{\emph{Notes:"The table reports the estimated child claim rate by state and year. The estimate is equal to the fraction of children appearing on a Form 1095 with an address in the specified state that are claimed on one or more tax returns for the specified year."} }}        
			\end{tabular}}
			\end{table});
#delimit cr